package com.zk.hql.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
@PropertySource("classpath:application-dat.properties")
public class DataSourceConfiguration {
    /***
     * 旧的数据源配置
     */
    @Autowired
    private DataSourceJPAProperties jpaProperties;
    //    创建数据源
    @Bean(name = "jpaDataSource")
    @Qualifier("jpaDataSource")
    @Primary
    public DataSource firstDataSource() {
        DataSource build =  DataSourceBuilder.create()
                .driverClassName(jpaProperties.getDriverClassName())
                .url(jpaProperties.getUrl())
                .username(jpaProperties.getUsername())
                .password(jpaProperties.getPassword())
                .build();;
        return build;
    }

}
